﻿/*******************************************************************************
* 
*Author         :  VN
*Description    :  网络发包缓存队列
*Other          :  none
*Modify Record  :  none
*
*******************************************************************************/
using System.Collections.Generic;
using System.Collections;

namespace Network
{
    public class PackCacheQueue
    {
        List<MsgInfo> m_list = new List<MsgInfo>();
        
        public void Push_Back(MsgInfo info)
        {
            m_list.Add(info);
        }

        public void Push_Front(MsgInfo info)
        {
            m_list.Insert(0, info);
        }

        public void CopyToFront(PackCacheQueue infos)
        {
            int nCount = infos.m_list.Count;
            for (int i = nCount; i > 0; --i)
            {
                m_list.Insert(0, infos.m_list[i - 1]);
            }
        }

        public void Remove(MsgInfo info)
        {
            if (m_list.Count > 0)
            {
                m_list.Remove(info);
            }
        }

        public bool IsEmpty()
        {
            return m_list.Count == 0;
        }

        public MsgInfo Pop()
                                {
            if (m_list.Count > 0)
            {
                MsgInfo info = m_list[0];
                m_list.RemoveAt(0);
                return info;
            }
            else
            {
                return null;
            }
        }

        public MsgInfo Find(uint uSeqID)
        {
            for (int i = 0; i < m_list.Count; ++i)
            {
                if (uSeqID == m_list[i].uSeqId)
                {
                    return m_list[i];
                }
            }
            return null;
        }

        public MsgInfo Peek()
        {
            if (m_list.Count > 0)
            {
                return m_list[0];
            }
            else
            {
                return null;
            }
        }

        public List<MsgInfo>  GetAll()
        {
            return m_list;
        }

        public void ClearAll()
        {
            m_list.Clear();
        }
    }
}